//
//  TabBarController.m
//  YuDing
//
//  Created by MT on 2017/7/29.
//  Copyright © 2017年 MT. All rights reserved.
//

#import "TabBarController.h"
#import "MapViewController.h"
#import "AccountViewController.h"
#import "MineViewController.h"

@interface TabBarController ()


@end

@implementation TabBarController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];
    
    [UITabBar appearance].translucent = NO;
    
    // 添加子控制器
    [self setUpAllChildViewController];
}

/**
 *  添加所有子控制器方法
 */
- (void)setUpAllChildViewController{
    //附近门店
    MapViewController *MapVC = [[MapViewController alloc] init];
    [self setUpOneChildViewController:MapVC image:[UIImage imageNamed:@"menu_icon_map_default"]  selectImage:[UIImage imageNamed:@"menu_icon_map_pre"] title:@"附近门店"];
    
    //账本管理
    AccountViewController *AccountVC = [[AccountViewController alloc] init];
    [self setUpOneChildViewController:AccountVC image:[UIImage imageNamed:@"menu_icon_account_default"]  selectImage:[UIImage imageNamed:@"menu_icon_account_pre"] title:@"账本管理"];
    
    //个人中心
    MineViewController *MineVC = [[MineViewController alloc] init];
    [self setUpOneChildViewController:MineVC image:[UIImage imageNamed:@"menu_icon_mine_default"] selectImage:[UIImage imageNamed:@"menu_icon_mine_pre"] title:@"个人中心"];
}

/**
 *  添加一个子控制器的方法
 */
- (void)setUpOneChildViewController:(UIViewController *)viewController image:(UIImage *)image selectImage:(UIImage *)selectImage title:(NSString *)title{
    {
        UINavigationController *navC = [[UINavigationController alloc]initWithRootViewController:viewController];
        
        navC.title = title;
        
        viewController.navigationItem.title = title;
        
        navC.tabBarItem.image = image;
        
        navC.navigationBar.tintColor = [UIColor whiteColor];
        
        UIImage *backButtonImage = [[UIImage imageNamed:@"nav_white"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        navC.navigationBar.backIndicatorImage = backButtonImage;
        navC.navigationBar.backIndicatorTransitionMaskImage = backButtonImage;
        
        // 设置 tabbarItem 选中状态的图片(不被系统默认渲染,显示图像原始颜色)
        UIImage * OriginalImage = [selectImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        
        [navC.tabBarItem setSelectedImage:OriginalImage];
        
        // 设置 tabbarItem 选中状态下的文字颜色(不被系统默认渲染,显示文字自定义颜色)
        NSDictionary *dictHome = [NSDictionary dictionaryWithObject:ColorWithRGB(28, 160, 242) forKey:NSForegroundColorAttributeName];
        [navC.tabBarItem setTitleTextAttributes:dictHome forState:UIControlStateSelected];
        
        [self addChildViewController:navC];
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
